import Vue from 'vue'
import Router from 'vue-router'
import Index from './views/Index'
import Login from './views/Login'
import UserInfo from './views/UserInfo'
import UserHistory from './components/UserHistory'
import Test from './views/Test'
// import {setLocation} from "./util/locationUtil";

Vue.use(Router)

const router = new Router({
    mode: 'history',
    routes: [
        {
            path: '',
            redirect: "/index",
        },
        {
            path: '/index',
            name: 'index',
            component: Index,
            meta: {
                title: '首页'
            }
        },
        {
            path: '/login',
            name: 'login',
            component: Login,
            meta: {
                title: '登录'
            }
        },
        {
            path: '/user',
            component: UserInfo,
            children: [
                {
                    path: 'index',
                    name: 'userHistory',
                    component: UserHistory,
                    meta: {
                        title: '用户记录'
                    },
                },
                {
                    path: 'test',
                    name: 'userTest',
                    component: Test,
                    meta: {
                        title: 'mbti测试'
                    },
                }
            ]
        },
        // {
        //     path: '/404',
        //     name: '404',
        //     component: PageContainer
        // },
        // {
        //     path: '*',
        //     name: 'PageContainer',
        //     component: PageContainer
        // },
    ]
})

const whiteList = ['/login', '/404']
// router.beforeEach((to, from, next) => {
//     // 登录验证
//     const token = localStorage.getItem('Authorization');
//     if (token) {
//         if (to.path === '/login') {
//             next({path: '/home'})
//         } else {
//             // todo 权限拦截
//             setLocation(to.meta.title);
//             next();
//         }
//     } else {
//         if (whiteList.indexOf(to.path) !== -1) {
//             next();
//         } else {
//             next({path: '/login'})
//         }
//     }
//
//     // setLocation(to.meta.title);
//     // next();
// })

export default router;
